package com.woniuxy.springmvcannotation;

import com.woniuxy.springnvcannotation.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author linke
 * @version 1.0
 * @className: HeaderController
 * @description: 接收请求头内容(了解)，通过@RequestHeader获得请求头内容    一般不需要获取
 * @date 2021/11/13 18:14
 * @Controller 将控制器交给spring容器管理
 * @RequestMapper 定义页面请求路径，与执行该路径请求的 方法之间的映射关系
 */
@Controller
@RequestMapping("header")
public class HeaderController {
    /**
     * @param model
     * @param userBean
     * @param sessionID 返回Cookie内容
     * @param userAgent 返回请求头的内容
     * @return 返回的字符串，就是需要跳转的页面
     */
    @RequestMapping(value = "/login")
    public String login(Model model, UserBean userBean,
                        @CookieValue("JSESSIONID") String sessionID, @RequestHeader("User-Agent") String userAgent) {
        System.out.println(userBean);//UserBean(id=null, userName=null, loginName=23, password=42242, age=null)
        System.out.println(sessionID);//59EEBDDEDB3F046CBB6F28D3002F6777
        System.out.println(userAgent);//Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36

        userBean.setUserName("张三");
        model.addAttribute("user", userBean);
        return "sysmag/main";
    }
}